home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form VBSqueeze
- BackColor = &H00C0C0C0&
- BorderStyle = 1 'Fixed Single
- Caption = "VB Squeeze"
- ClientHeight = 405
- ClientLeft = 1110
- ClientTop = 1545
- ClientWidth = 1725
- Height = 810
- Left = 1050
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 405
- ScaleWidth = 1725
- Top = 1200
- Width = 1845
- Begin CommandButton btnSave
- Caption = "&Save/Load Text"
- Height = 375
- Left = 15
- TabIndex = 0
- Top = 15
- Width = 1695
- End
- '*************************************************************'
- '* VB SQUEEZE *'
- '* *'
- '* What is it? *'
- '* VB Squeeze is another useful(hopefully) little utility *'
- '* that will save some of you some time and make your life *'
- '* a little easier. *'
- '* *'
- '* What does it do? *'
- '* We all know that VB accumualates extra garbage in our *'
- '* Form files, and such, while we work, and the only way to *'
- '* get rid of it is to do a SaveText/LoadText for each of *'
- '* our forms. This can get to be very tedious indeed, so *'
- '* VB Squeeze will do it for you, for each file in your *'
- '* project. *'
- '* *'
- '* How does it work? *'
- '* VB Squeeze uses SendKeys to activate VB and perform the *'
- '* necessary operations on each file. *'
- '* *'
- '* WARNING! *'
- '* I just got this idea and wanted to see if it would *'
- '* work so I threw it together very quickly. The code is *'
- '* commented but you will want to look it over for obvious *'
- '* bugs that I missed and places to improve it(like error *'
- '* checking of some sort). Since it relies on SendKeys it *'
- '* is not the most reliable method of doing this but, hey, *'
- '* it works. USE IT AT YOUR OWN RISK. If you modify and *'
- '* improve it I would love to hear about it. If you think *'
- '* it's a lousy idea and a complete waste of time I want *'
- '* to know that too. *'
- '* *'
- '* PLEASE! *'
- '* Look through the code before you run it(and don't use *'
- '* it on anything important at first) so you know what it *'
- '* does to get the job done. You may want to modify it to *'
- '* operate on a single file instead of all the files in *'
- '* your project. *'
- '* *'
- '* NOTES: *'
- '* The biggest note is this. If you have two files with *'
- '* the same prefix(i.e. MYAPP.FRM & MYAPP.BAS) then *'
- '* VB Squeeze will stop if they are consecutive in the *'
- '* project window(the global file seems to be the biggest *'
- '* culprit). The reason is this. As VB Squeeze moves down *'
- '* the list of files in the project window it compares the *'
- '* name of the last file with that of the current file, *'
- '* and, if they match, it assumes it's at the last file. *'
- '* I hope someone comes up with a better method for this. *'
- '* *'
- '* Why does only the prefix need to match? The filename is *'
- '* taken from the Code|Save dialog box and .TXT is appended *'
- '* automatically. *'
- '* *'
- '* Error checking doesn't exist. You will want to add this *'
- '* for safety(check for pre-existing files and such). *'
- '* *'
- '* IMPROVEMENTS: *'
- '* Please do! I don't have the time to really make this a *'
- '* priority project and I HATE doing the SaveText/LoadText *'
- '* mambo. *'
- '* *'
- '* Maybe the saved text could be opened and all the *'
- '* comments and blank lines could be stripped to comapct *'
- '* code before compilation. *'
- '* *'
- '* Comments? Suggestions? I want 'em! *'
- '* *'
- '* Gregg Irwin CIS:ID 72450,676 *'
- '*************************************************************'
- DefInt A-Z
- Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
- Declare Function GetActiveWindow Lib "User" () As Integer
- Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal nMaxChars As Integer) As Integer
- Declare Function SetActiveWindow Lib "User" (ByVal hWnd As Integer) As Integer
- 'Const NULL = 0& '--If you want to pass NULL to FindWindow
- Dim FileName As String
- Dim OldFileName As String
- Sub btnSave_Click ()
- '-- Class name for VB = "wndclass_desked_gsk"
- '-- Caption for VB = "Microsoft Visual Basic [design]"
- VBhWnd = FindWindow("wndclass_desked_gsk", "Microsoft Visual Basic [design]")
-
- If Len(VBhWnd) Then '-- Make sure VB is running before we do anything
- ActivehWnd = GetActiveWindow()
- If VBhWnd <> ActivehWnd Then '-- If VB isn't active then activate it.
- PrevhWnd = SetActiveWindow(VBhWnd) '-- Save the handle of the currently active window
- End If ' and activate VB.
-
- Clipboard.Clear '-- Start with a clean clipboard
- OldFileName = "!@#$%^&*()" '-- Initialize OldFileName so we don't have
- ' a match by accident or coinicidence.
- '------------------------------------------------------
- '-- Move to first file in project window
- '------------------------------------------------------
- Do
- SendKeys "%{F6}", True '-- Move to next VB owned window
- WndCaption$ = Space$(13) '-- Initialize a string for an API call
- RtnLen = GetWindowText(GetActiveWindow(), WndCaption$, 12) '-- Get Window caption
- WndCaption$ = Left$(WndCaption$, RtnLen) '-- Strip Chr$(0)
- If Right$(WndCaption$, 3) = "MAK" Then Exit Do '-- We found the project window
- Loop
- SendKeys "{HOME}" '-- Move to first file
-
- '------------------------------------------------------
- '-- For each file in the project...
- ' Save the code as text and then reload it to get
- ' rid of all the old trash that hangs around.
- '------------------------------------------------------
- Do While OldFileName <> FileName
- OldFileName = FileName '-- Reset file name for next iteration
-
- SendKeys "%CS", True '-- Code|Save
- x = DoEvents()
-
- SendKeys "^{INSERT}{ENTER}", True '-- Clip filename to clipboard & Save txt file
- x = DoEvents()
-
- FileName = Clipboard.GetText(1) '-- Save filename in variable
-
- '------------------------------------------------------
- '-- Find the project window
- '------------------------------------------------------
- Do
- SendKeys "%{F6}", True '-- Move to next VB owned window
- WndCaption$ = Space$(13) '-- Initialize a string for an API call
- RtnLen = GetWindowText(GetActiveWindow(), WndCaption$, 12) '-- Get Window caption
- WndCaption$ = Left$(WndCaption$, RtnLen) '-- Strip Chr$(0)
- If Right$(WndCaption$, 3) = "MAK" Then Exit Do '-- We found the project window
- Loop
- x = DoEvents()
-
- '------------------------------------------------------
- '-- If you don't open the code window before loading
- ' the text it will load as a separate module.
- '------------------------------------------------------
- SendKeys "{F7}", True '--Open code window
- x = DoEvents()
-
- SendKeys "%CL", True '--Code|Load
- x = DoEvents()
-
- SendKeys "+{INSERT}%R", True '--Paste filename & Click "&Replace"
- x = DoEvents()
-
- '------------------------------------------------------
- '-- Close the window before moving to the next file
- ' otherwise the focus won't be in the project
- ' window(and you're in big trouble then).
- '------------------------------------------------------
- SendKeys "% %{F4}" '--System Menu|Close
- x = DoEvents()
- '****************************************************************'
- '* *'
- '* NOTE: The File|Save command is commented out for good *'
- '* reason. As I was working on this I ran the program *'
- '* to test it and it ate my file(becuase it loads the *'
- '* text in over the original file code). I consider *'
- '* this to be a bad thing. I recommend that you let it *'
- '* Save/Load-Text all your files and then look at them *'
- '* to make sure it all worked *before* you save them. *'
- '* This is a quick hack with very little planning and *'
- '* forethought behind it. MAKE NO ASSUMPTION THAT IT *'
- '* IS A FULLY TESTED PROGRAM THAT WILL WORK FOR YOU!!! *'
- '* I say this because it works on your entire project *'
- '* and could destroy a lot of work. I am posting this *'
- '* app and all it's source in the hopes that someone *'
- '* will find it useful(and maybe improve it as well). *'
- '* I don't have time right now to make it bulletproof. *'
- '* *'
- '****************************************************************'
-
- '**SendKeys "%FS", TRUE '--File|Save
-
- SendKeys "{DOWN}", True '--Move to next file
- Loop
-
- Else
- MsgBox "Visual Basic is not running", MB_OK, "VB Squeeze...Didn't"
- End If 'Len(VBhWnd)
- '-- Un-REM this to re-activate the window that was
- ' active when we started.
- 'dummy = SetActiveWindow(PrevhWnd)
- End Sub
- Sub Form_Unload (Cancel As Integer)
- End
- End Sub
-